Skip to content

CMS-204 | Show clear Studio project/config mismatch error instead of cryptic schema hash mismatch#105

Merged
woywro merged 2 commits intomainfrom
CMS-204
Apr 17, 2026
Merged

CMS-204 | Show clear Studio project/config mismatch error instead of cryptic schema hash mismatch#105
woywro merged 2 commits intomainfrom
CMS-204

Conversation

@woywro
Copy link
Copy Markdown
Collaborator

@woywro woywro commented Apr 17, 2026

Summary by CodeRabbit

  • New Features
    • Detects project configuration mismatches and shows a prominent "Configuration mismatch" alert with configured vs. resolved project and environment.
    • Server responses now include the resolved project identifier when available.
  • Bug Fixes / Validation
    • Validates the optional project field (must be non-empty when present).
  • Tests
    • Added unit and integration tests covering project field handling and mismatch flows.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fb0feea1-4b8e-47e2-af10-c7ca8168c804

📥 Commits

Reviewing files that changed from the base of the PR and between faab732 and 7e770b2.

📒 Files selected for processing (4)
  • .claude/worktrees/agent-a53852dc
  • packages/shared/src/lib/contracts/schema.test.ts
  • packages/shared/src/lib/contracts/schema.ts
  • packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx
✅ Files skipped from review due to trivial changes (1)
  • packages/shared/src/lib/contracts/schema.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/lib/contracts/schema.ts

📝 Walkthrough

Walkthrough

The PR adds optional project tracking to the schema list API and propagates project-mismatch detection through validation, studio state, and UI. The server returns data.project; the shared contract validates it; the studio state can now be "project-mismatch" and the UI shows matching messages and denies writes.

Changes

Cohort / File(s) Summary
Schema API Route & Test
apps/server/src/lib/schema-api.ts, apps/server/src/lib/schema-api.test.ts
GET /api/v1/schema now includes data.project set from resolved scope; test added to assert response contains data.project === "my-project".
Shared Contract & Tests
packages/shared/src/lib/contracts/schema.ts, packages/shared/src/lib/contracts/schema.test.ts
SchemaRegistryListResponse gains optional project?: string; validator enforces non-empty trimmed string when present; tests added for present, absent, empty, and whitespace-only cases.
Studio Schema State & Tests
packages/studio/src/lib/schema-state.ts, packages/studio/src/lib/schema-state.test.ts
Introduced exported StudioSchemaProjectMismatchState and added it to StudioSchemaState union; loadStudioSchemaState now returns "project-mismatch" if server data.project differs from config; tests cover match, mismatch, and missing-project scenarios.
Studio UI Pages
packages/studio/src/lib/runtime-ui/app/admin/schema-page.tsx, packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx
UI displays a "Project mismatch" / "Configuration mismatch" section when state is "project-mismatch"; content document page shows a project-mismatch banner, suppresses redundant messages, and treats mismatch as non-writable.
Misc / Submodule
.claude/worktrees/agent-a53852dc
Git submodule pointer updated to commit 7a81861....

Sequence Diagram

sequenceDiagram
    participant Client
    participant API
    participant Validator
    participant SchemaState
    participant UI

    Client->>API: GET /api/v1/schema (with x-mdcms-project)
    API->>API: resolve project from header
    API-->>Client: 200 { data: { project: "server-project", ... } }

    Client->>Validator: validateSchemaRegistryListResponse(response)
    Validator-->>Client: { project: "server-project", ... }

    Client->>SchemaState: loadStudioSchemaState(listResult, config)
    SchemaState->>SchemaState: compare listResult.project vs config.project

    alt projects match or project absent
        SchemaState->>SchemaState: continue schema loading, hash/capability checks
        SchemaState-->>Client: { status: "ready", ... }
        Client->>UI: render schema browser
    else projects mismatch
        SchemaState-->>Client: { status: "project-mismatch", configProject, serverProject, environment }
        Client->>UI: render project-mismatch banner / deny writes
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇
I hopped to the server, nose in the tree,
Found projects that whispered, "This isn't me!"
Now headers proclaim where each schema belongs,
If names disagree, I sing mismatch songs.
Hooray — no more guessing where projects flee!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main objective: adding detection and clear presentation of project/config mismatches instead of cryptic schema hash errors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CMS-204

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/server/src/lib/schema-api.ts`:
- Line 834: The code is echoing client-provided scope.project into the response
(making Studio's project-mismatch useless); instead derive the authoritative
project from the server-side authenticated context or a server lookup. Replace
uses of scope.project when setting data.project with the server-determined value
(for example requestContext.user.projectId or the result of a helper like
getProjectForUser(user.id) / resolveProjectForAccount(accountId)), and if
necessary add a lookup function call (e.g., getProjectForUser or
getProjectByAccount) before returning the payload so data.project is set from
that authoritative source rather than scope.project.

In `@packages/shared/src/lib/contracts/schema.ts`:
- Around line 76-81: The validation allows empty project strings; update the
check in the payload validation around the local variable project so that a
blank string is rejected: change the condition to ensure project is either
undefined or a non-empty string (e.g. project !== undefined && (typeof project
!== "string" || project.trim() === "")) and call
invalidInput(`${context}.project`, "must be a non-empty string or undefined.", {
project }) to fail on empty values.

In `@packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx`:
- Around line 2719-2726: The dedicated project-mismatch banner branch (checking
state.schemaState?.status === "project-mismatch" and calling
renderProjectMismatchBanner) causes a duplicate generic read-only message later
because that later conditional only excludes "schema-hash-mismatch"; update that
later conditional to also exclude "project-mismatch" (i.e., treat
state.schemaState?.status === "project-mismatch" the same as schema-hash
mismatch) so when renderProjectMismatchBanner is shown the generic read-only
message is suppressed; locate the JSX that renders the generic read-only message
(the conditional that currently checks for schema-hash mismatch) and add the
additional check for "project-mismatch".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 728f1b56-9778-4d66-8e17-058adafc7baf

📥 Commits

Reviewing files that changed from the base of the PR and between cb996af and faab732.

📒 Files selected for processing (8)
  • apps/server/src/lib/schema-api.test.ts
  • apps/server/src/lib/schema-api.ts
  • packages/shared/src/lib/contracts/schema.test.ts
  • packages/shared/src/lib/contracts/schema.ts
  • packages/studio/src/lib/runtime-ui/app/admin/schema-page.tsx
  • packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx
  • packages/studio/src/lib/schema-state.test.ts
  • packages/studio/src/lib/schema-state.ts

Comment thread apps/server/src/lib/schema-api.ts
Comment thread packages/shared/src/lib/contracts/schema.ts
Comment thread packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx
@woywro woywro merged commit 363b414 into main Apr 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant